package com.xy.project.lhyz.config;

import com.xy.core.constant.FnKit;
import com.xy.etl.opc.model.OpcConfig;
import com.xy.project.lhyz.vo.ParamVO;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class SelfOpcConfig extends OpcConfig {

    /**
     * 租户
     */
    private String tenantId = "111111";

    /**
     * 类型
     */
    private String type;
    /**
     * 属性列表
     */
    private List<String> keyList;


    private List<ParamVO> paramVOS = null;

    public void init() {
        paramVOS = new ArrayList<>();
        for (String key : keyList) {
            String[] ks = key.split(",");
            paramVOS.add(new ParamVO(ks[0].trim(), ks[1].trim()));
        }
    }

    public List<String> getOpcKeyList() {
        return FnKit.extract(paramVOS, e -> e.getOpcKey());
    }

    public String getKey(String opcKey) {
        if(paramVOS != null){
            for (ParamVO paramVO : paramVOS) {
                if(paramVO.getOpcKey().equalsIgnoreCase(opcKey)){
                    return paramVO.getBusiKey();
                }
            }
        }
        return null;

    }
}
